<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input
        v-model="listQuery.videoName"
        clearable
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入课程名称"
      />
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查询</el-button>
    </div>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" width="100px" label="课程ID" prop="id" />

      <el-table-column align="center" label="课程名称" prop="username" />

      <el-table-column align="center" label="限制" prop="mobile" />
      <el-table-column align="center" label="视频数量" prop="birthday" />
      <el-table-column align="center" label="状态" prop="mobile" />
      <el-table-column align="center" label="排序" prop="mobile" />
      <el-table-column align="center" label="播放量" prop="mobile" />
      <el-table-column align="center" label="创建时间" prop="createTime" />
      <el-table-column align="center" label="操作" prop="status">
        <template>
          <el-button type="text">详情</el-button>
          <el-button type="text">删除</el-button>
          <el-button type="text">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { fetchList } from '@/api/video'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'User',
  components: { Pagination },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: false,
      listQuery: {
        index: 0,
        size: 20,
        videoName: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery)
        .then(response => {
          this.list = response.data.data.content
          this.total = response.data.data.totalPages
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.index = 0
      this.getList()
    }
  }
}
</script>
